#include <libpaysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int GetOpCode(char* op)
{
    if(!op || !*op) return -1;
    if(!strcmp(op,"mt")) return 0;
    if(!strcmp(op,"es")) return 1;
    if(!strcmp(op,"be")) return 2;
    if(!strcmp(op,"br")) return 3;
    if(!strcmp(op,"bb")) return 4;
    if(!strcmp(op,"me")) return 5;
    if(!strcmp(op,"nw")) return 6;
    if(!strcmp(op,"so")) return 7;
    if(!strcmp(op,"ze")) return 8;
    if(!strcmp(op,"nt")) return 9;
    return -1;
}


int main(int argc,char** argv)
{
    if(argc<6)
    {
	printf("USAGE: reqbatch [USER]:[PASS]@[HOST]/DBASE OPERATOR PHONE AMOUNT COUNT\n");
	return 0;
    }
    int method=REQ_PHONECHECK;
	
    int opcode=GetOpCode(argv[2]);
    if(opcode<0)
    {
	printf("unknown operator\n");
	return 0;
    }
	
    CMySQLConnection sql;
    if(!sql.Connect(argv[1]))
	printf("%s\n",sql.GetLastError());
    else
    {
	for(int i=0;i<atoi(argv[5]);i++)
	{
	    CPayRequest req(sql);
	    int n=req.SendRequest(method,opcode,argv[3],atof(argv[4])+(double)i);
	    if(n<0)
	    {
	        printf("%s\n",sql.GetLastError());
		break;
	    }
	    else printf("%i- SUCCESS. REQID=%i\n",i+1,n);
	}
    }
    return 0;
}
